<?php
include "base.php";

// 从尾部插入
function arrayPushTest(){
    $a=array("red","green");
    array_push($a,"blue","yellow");
    $a[] = "blac";
    p($a);
}

// 删除最后一个元素
function arrayPopTest(){
    $a=array("red","green","blue");
    array_pop($a);
    unset($a[2]);
    p($a);
}

// 删除第一个元素返回新的数组
function arrayShiftTset(){
    $a=array("a"=>"red","b"=>"green","c"=>"blue");
    echo array_shift($a);
    p($a);
}


// 从头插入元素
function arrayUnshiftTset(){
    $a=array("a"=>"red","b"=>"green");
    array_unshift($a,"blue");
    p($a);
}

function arrayFilterTest(){
    $a1=array(2,3,4,5);
    $ret = array_filter($a1,"test_odd");
    p($a1);
    p($ret);
}

// 将数组的值 加减乘除本身并返回新的数组
function myfunction($num)
{
    return($num+$num);
}
function arrayMapTest(){
    $a=array(1,2,3,4,5);
    p(array_map("myfunction",$a));
}


//对数组中的每个元素应用用户自定义函数
function myfunction1($value,$key)
{
    echo "李江浩{$key}嘎嘎 $value<br>";
}
function arrayWalkTest(){
    $a=array("a"=>"red","b"=>"green","c"=>"blue");
    array_walk($a,"myfunction1");
}
$GLOBALS["ar"]();